
# ifndef __DFX_VERTEX_MANAGER_H__
# define __DFX_VERTEX_MANAGER_H__

# include "dfxCore.h"
# include "dfxSingleton.h"
# include "dfxVertexFormat.h"
# include "dfxMaterial.h"
# include "dfxRenderData.h"

namespace DFX
{
    class GraphicsDevice;

    class DFX_EXPORT VertexManager : public Singleton<VertexManager>
    {
    protected:

        UInt32          mNumCaches;
        GraphicsDevice  *mGraphicsDevice;
        PRIMITIVE_TYPE  mPrimitiveType;

    public:

        VertexManager(GraphicsDevice *gd, UInt32 numCaches)
            : mGraphicsDevice(gd), mNumCaches(numCaches)
        {
        }

        virtual ~VertexManager()
        {
        }

        GraphicsDevice* GetGraphicsDevice() const
        {
            return mGraphicsDevice;
        }

        UInt32 GetNumCaches() const
        {
            return mNumCaches;
        }        

        PRIMITIVE_TYPE GetPrimitiveType() const
        {
            return mPrimitiveType;
        }

        void SetPrimitiveType(PRIMITIVE_TYPE type)
        {
            mPrimitiveType = type;
        }

        virtual DFXRESULT AddVertexFormat(VertexFormat *format, UInt32 *formatId) = 0;
        virtual DFXRESULT RemoveVertexFormat(UInt32 formatId) = 0;

        virtual DFXRESULT CreateBuffer(UInt32 formatId, Material *material, UInt32 pass,
            UInt32 numVertices, UInt32 numIndices, UInt32 indexSize, const void *vertices, 
            const void *indices, UInt32 *bufferId) = 0;

        virtual DFXRESULT Render(UInt32 formatId, Material *material, UInt32 pass,
            UInt32 numVertices, UInt32 numIndices, const void *vertices, const void *indices = 0) = 0;

        virtual DFXRESULT RenderVertices(UInt32 numVertices, const void *vertices,
            Material *material, UInt32 pass) = 0;

        virtual DFXRESULT Render(UInt32 bufferId) = 0;

        virtual DFXRESULT Render(UInt32 bufferId, Material *material, UInt32 pass,
            UInt32 startIndex, UInt32 numVertices, UInt32 numTris) = 0;

        virtual DFXRESULT RenderPoints(UInt32 formatId, UInt32 numVertices,
            const void *vertices, const Color4 &color) = 0;

        virtual DFXRESULT RenderLines(UInt32 formatId, UInt32 numVertices,
            const void *vertices, const Color4 &color) = 0;

        virtual DFXRESULT RenderLine(const Vector3 &start, const Vector3 &end, 
            const Color4 &color) = 0;

        virtual DFXRESULT ForcedRender(VertexFormat *format) = 0;
        virtual DFXRESULT ForcedRenderAll() = 0;

        virtual void InvalidateStates() = 0;
    };
}

# endif